from urllib.request import urlopen
import ssl

# 使用更可靠的莎士比亚文本来源
context = ssl._create_unverified_context()
shakespeare = ''
try:
    shakespeare = urlopen('https://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt',
                          context=context)
    print(shakespeare.read().decode('utf-8'))
except Exception as e:
    print(f"获取数据时出错: {e}")

words = set(shakespeare.read().decode().split())
print(words)
